package com.wxf.dao.impl;

import com.wxf.bean.DBUtils;
import com.wxf.bean.Grade;
import com.wxf.dao.GradeDao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class GradeDaoImpl extends DBUtils implements GradeDao {
    @Override
    public List<Grade> getGradeInfo() {
        StringBuffer sql = new StringBuffer("select * from grade");
        resultSet = query(sql.toString(),null);
        ArrayList<Grade>grades = new ArrayList<>();
        try {
            if(resultSet==null){
                return null;
            }
            while (resultSet.next()) {
                Grade grade = new Grade();
                grade.setGradeId(resultSet.getInt("gradeid"));
                grade.setGradeName(resultSet.getString("gradename"));
                grades.add(grade);
            }
            System.out.println(grades.size());
        }catch (SQLException e){
            e.printStackTrace();
        }finally {
            closeAll();
        }
        return  grades;
    }
}
